package Myqueue;

public class MyQueueList {
    public class ListNode{
        public ListNode next;
        public ListNode prve;
        public int val;
        public ListNode(int val){
            this.val=val;
        }
    }
    public ListNode head;
    public ListNode last;
    //查看队列头元素
    public int peek(){
        if(head==null){
            return -1;
        }
        return head.val;
    }
    //删除队列头元素
    public int delEleFirst(){
        if(head==null){
            return -1;
        }
        int num=head.val;
        if(head.next==null){
            head=last=null;
        }else {
            head=head.next;
            head.prve=null;
        }
        return num;
    }
    //删除任意位置元素(删除一个)
    public int delAny(int val){
        if(head==null){
            return -1;
        }
        if(head.val==val){
            int ret=head.val;
            head=head.next;
            head.prve=null;
            return ret;
        }
        ListNode cur=head.next;
        while(cur!=null){
            if(cur.val==val){
                break;
            }
            cur=cur.next;
        }
        cur.prve.next=cur.next;
        cur.next.prve=cur.prve;
        return cur.val;
    }
    //判断是否为空
    public boolean isEmpty(){
        if(head==null){
            return true;
        }
        return false;
    }
}
